package util.dbutil;

import bean.ChangeRoom;
import bean.Room;
import bean.Student;
import org.apache.commons.dbutils.QueryRunner;
import util.C3p0Util;

import java.sql.SQLException;

public class LoginChangeRoom {
    public int insertChangeRoom(ChangeRoom changeRoom){
        int count = 0;
        QueryRunner runner = new QueryRunner(C3p0Util.getDs());
        String sql = "insert into t_changeRoom (cr_s_number,cr_s_name,cru_r_number,cru_b_number,crn_r_number,crn_b_number) values (?,?,?,?,?,?)";

        try {
            /*
                - update DML 针对增、删、改的语句都可以使用
                    参数1：sql
                    参数2：可变数组，存放的是占位符对应的数据值
             */
            count = runner.update(sql,changeRoom.getCrsNumber(),changeRoom.getCrsName(),changeRoom.getCrurNumber(),changeRoom.getCrubNumber(),changeRoom.getCrnrNumber(),changeRoom.getCrnbNumber());
            if(count > 0){
                System.out.println("执行成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return count;
    }

    public int updateStudent(Student student){
        int count = 0;
        QueryRunner runner = new QueryRunner(C3p0Util.getDs());
        String sql = "update t_student set s_r_number=?,s_b_number=? where s_number=?";

        try {
            /*
                - update DML 针对增、删、改的语句都可以使用
                    参数1：sql
                    参数2：可变数组，存放的是占位符对应的数据值
             */
            count = runner.update(sql,student.getSrNumber(),student.getSbNumber(),student.getsNumber());
            if(count > 0){
                System.out.println("执行成功");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return count;
    }
}

